//
//  SEInquirySectionHeader.swift
//  SmartEyeForDoctor
//
//  Created by QDSG on 2021/4/20.
//

import UIKit

class SEInquirySectionHeader: UIView {
    
    var rejectedPrescription: (() -> Void)?
    var historyDiagnosis: (() -> Void)?

    @IBOutlet private weak var rejectedButton: UIButton!

    @IBOutlet private weak var historyButton: UIButton!
    
    @IBAction private func rejectedPrescriptionAction() {
        rejectedPrescription?()
    }
    
    @IBAction private func historyDiagnosisAction() {
        historyDiagnosis?()
    }

    func updateData(_ viewModel: SEInquiryViewModel) {
        let countStr = "\(viewModel.abortPrescriptionCount)"
        let normalAttributes = [NSAttributedString.Key.foregroundColor: Asset.textDark.color,
                                NSAttributedString.Key.font: UIFont.regular(14)]
        let normalAttrTitle = NSMutableAttributedString(string: "被驳回处方(\(countStr))", attributes: normalAttributes)

        let attributes = [NSAttributedString.Key.foregroundColor: UIColor(hex: "#FFB300"),
                          NSAttributedString.Key.font: UIFont.medium(16)]
        let attrTitle = NSAttributedString(string: countStr, attributes: attributes)
        normalAttrTitle.replaceCharacters(in: NSRange(location: 6, length: countStr.count), with: attrTitle)
        rejectedButton.titleLabel?.attributedText = normalAttrTitle
        rejectedButton.setAttributedTitle(normalAttrTitle, for: .normal)
    }

}
